package com.ynny.demo13.entity.mapper;

import com.ynny.demo13.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {
    @Select("""
            select * from tb_user
                    where username like concat('%' , #{username},'%') \s
            """)
    List<User> selectALl(String username);


    @Select("""
        
            SELECT u.*,p.*
                    FROM tb_user u
                    LEFT JOIN tb_user_product up
                    ON up.user_id = u.user_id
                    LEFT JOIN tb_product p
                    ON p.product_id = up.product_id
            """)
    List<User> selectAllUserAndProduct();

    @Insert("""
    insert into tb_user(username,password)
    values (#{username} , #{password} )

""")
    int insert(User user);

    @Update("""
    
    update tb_user set username = #{username} ,
    password = #{password} 
    where user_id = #{userId} 

""")
    int update(User user);

    @Delete("""

    delete from tb_user
    where user_id = #{userId} 
""")
    int delete(Integer userId);


}
